package Collection;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo {
    public static void main(String[] args) {
        //因为Collection是接口,不能创建对象，所以只能通过实现类创建
        Collection<String>collection = new ArrayList<>();
        //boolean add 添加
        //实现类是单列可重复的
        collection.add("ABC");
        collection.add("abc");
        collection.add("abc");
        collection.add("aaaa");
        System.out.println(collection);

        //boolean remove(Object o) 从集合删除指定元素
        //删除成功 返回ture    失败 返回false
       // boolean remove1 = collection.remove("123");
       // boolean remove2 = collection.remove("abc");
       // System.out.println(collection);

        //判断集合是否存在，返回的是布尔类型
        boolean contains = collection.contains("abc");
        System.out.println(contains);


        //判断集合是为否为空
        boolean empty = collection.isEmpty();
        System.out.println(empty);

        //集合长度
        int size = collection.size();
        System.out.println(size);

    }

    private static void method2(Collection<String> collection) {
        //boolean removeif(Object o)  根据条件进行删除
        //boolean test(String t);  他是删除字符串的长度，不是删除集合里面的元素

        collection.removeIf(
                 s-> s.length() == 3
        );
        System.out.println(collection.toString());
    }

    private static void method1(Collection<String> collection) {
        //就是将集合中所有元素删除
        collection.clear();
        System.out.println(collection);
    }
}
